将一个int从python套接字发送到java套接字

时间:2016-01-21 22:04:38

标签: java python sockets networking

我目前正致力于获取一个python套接字以将整数发送到java套接字,因此java套接字可以读取一个字节数组,该数组代表此步骤之后的字符串。

我尝试在结构中发送int但是在java端返回一个大量的数字。

p = struct.pack('i', len(data))
clientsocket.send(p)

1 个答案:

答案 0 :(得分:2)

https://docs.python.org/2/library/struct.html

查看7.3.2.1。通过网络发送任何数据时,始终将其转换为网络字节顺序。您的上述代码将是:

#include <iostream>
#include <cmath>

int main ()
{
using namespace std;

int speed; 

cout << "What is the wind speed in MPH?" << endl;
cin >> speed;

//input wind speed
//output storm classification

switch (speed)
{

case (1):
cout << "This is not a hurricane." << endl;
break; 

case (2):
cout << "This is not a hurricane." << endl;
break; 
case (3):
cout << "This is not a hurricane." << endl;
break; 
case (4):
cout << "This is not a hurricane." << endl;
break; 
case (5):
cout << "This is not a hurricane." << endl;
break; 
case (6):
cout << "This is not a hurricane." << endl;
break; 
case (7):
cout << "This is not a hurricane." << endl;
break; 
case (8):
cout << "This is not a hurricane." << endl;
break; 
case (9):
cout << "This is not a hurricane." << endl;
break; 
case (10):
cout << "This is not a hurricane." << endl;
break; 
case (11):
cout << "This is not a hurricane." << endl;
break; 
case (12):
cout << "This is not a hurricane." << endl;
break; 
case (13):
cout << "This is not a hurricane." << endl;
break; 
case (14):
cout << "This is not a hurricane." << endl;
break; 
case (15):
cout << "This is not a hurricane." << endl;
break; 
case (16):
cout << "This is not a hurricane." << endl;
break;
case (17):
cout << "This is not a hurricane." << endl;
break; 
case (18):
cout << "This is not a hurricane." << endl;
break; 
case (19):
cout << "This is not a hurricane." << endl;
break; 
case (20):
cout << "This is not a hurricane." << endl;
break; 
case (21):
cout << "This is not a hurricane." << endl;
break; 
case (22):
cout << "This is not a hurricane." << endl;
break; 
case (23):
cout << "This is not a hurricane." << endl;
break; 
case (24):
cout << "This is not a hurricane." << endl;
break; 
case (25):
cout << "This is not a hurricane." << endl;
break; 
case (26):
cout << "This is not a hurricane." << endl;
break; 
case (27):
cout << "This is not a hurricane." << endl;
break; 
case (28):
cout << "This is not a hurricane." << endl;
break; 
case (29):
cout << "This is not a hurricane." << endl;
break; 
case (30):
cout << "This is not a hurricane." << endl;
break; 
case (31):
cout << "This is not a hurricane." << endl;
break; 
case (32):
cout << "This is not a hurricane." << endl;
break; 
case (33):
cout << "This is not a hurricane." << endl;
break; 
case (34):
cout << "This is not a hurricane." << endl;
break; 
case (35):
cout << "This is not a hurricane." << endl;
break; 
case (36):
cout << "This is not a hurricane." << endl;
break; 
case (37):
cout << "This is not a hurricane." << endl;
break; 
case (38):
cout << "This is not a hurricane." << endl;
break; 
case (39):
cout << "This is not a hurricane." << endl;
break; 
case (40):
cout << "This is not a hurricane." << endl;
break; 
case (41):
cout << "This is not a hurricane." << endl;
break; 
case (42):
cout << "This is not a hurricane." << endl;
break; 
case (43):
cout << "This is not a hurricane." << endl;
break; 
case (44):
cout << "This is not a hurricane." << endl;
break; 
case (45):
cout << "This is not a hurricane." << endl;
break; 
case (46):
cout << "This is not a hurricane." << endl;
break; 
case (47):
cout << "This is not a hurricane." << endl;
break; 
case (48):
cout << "This is not a hurricane." << endl;
break; 
case (49):
cout << "This is not a hurricane." << endl;
break; 
case (50):
cout << "This is not a hurricane." << endl;
break; 
case (51):
cout << "This is not a hurricane." << endl;
break; 
case (52):
cout << "This is not a hurricane." << endl;
break; 
case (53):
cout << "This is not a hurricane." << endl;
break; 
case (54):
cout << "This is not a hurricane." << endl;
break; 
case (55):
cout << "This is not a hurricane." << endl;
break; 
case (56):
cout << "This is not a hurricane." << endl;
break; 
case (57):
cout << "This is not a hurricane." << endl;
break; 
case (58):
cout << "This is not a hurricane." << endl;
break; 
case (59):
cout << "This is not a hurricane." << endl;
break; 
case (60):
cout << "This is not a hurricane." << endl;
break; 
case (61):
cout << "This is not a hurricane." << endl;
break; 
case (62):
cout << "This is not a hurricane." << endl;
break; 
case (63):
cout << "This is not a hurricane." << endl;
break; 
case (64):
cout << "This is not a hurricane." << endl;
break; 
case (65):
cout << "This is not a hurricane." << endl;
break; 
case (66):
cout << "This is not a hurricane." << endl;
break; 
case (67):
cout << "This is not a hurricane." << endl;
break; 
case (68):
cout << "This is not a hurricane." << endl;
break; 
case (69):
cout << "This is not a hurricane." << endl;
break; 
case (70):
cout << "This is not a hurricane." << endl;
break; 
case (71):
cout << "This is not a hurricane." << endl;
break; 
case (72):
cout << "This is not a hurricane." << endl;
break; 

case (73):
cout << "This is not a hurricane." << endl;
break; 

case (74):
cout << "This is a Class 1 hurricane." << endl;
break; 

case (75):
cout << "This is a Class 1 hurricane." << endl;
break; 

case (76):
cout << "This is a Class 1 hurricane." << endl;
break; 

case (77):
cout << "This is a Class 1 hurricane." << endl;
break; 

case (78):
cout << "This is a Class 1 hurricane." << endl;
break; 

case (79):
cout << "This is a Class 1 hurricane." << endl;
break; 

case (80):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (81):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (82):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (83):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (84):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (85):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (86):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (87):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (88):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (89):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (90):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (91):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (92):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (93):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (94):
cout << "This is a Class 1 hurricane." << endl;
break; 
case (95):
cout << "This is a Class 1 hurricane." << endl;
break; 

case (96): 
cout << "This is a class 2 hurricane." << endl;
break;

case (97): 
cout << "This is a class 2 hurricane." << endl;
break;

case (98): 
cout << "This is a class 2 hurricane." << endl;
break;

case (99):
cout << "This is a class 2 hurricane." << endl;
break;

case (100): 
cout << "This is a class 2 hurricane." << endl;
break;

case (101): 
cout << "This is a class 2 hurricane." << endl;
break;

case (102): 
cout << "This is a class 2 hurricane." << endl;
break;

case (103): 
cout << "This is a class 2 hurricane." << endl;
break;

case (104): 
cout << "This is a class 2 hurricane." << endl;
break;

case (105): 
cout << "This is a class 2 hurricane." << endl;
break;

case (106): 
cout << "This is a class 2 hurricane." << endl;
break;

case (107): 
cout << "This is a class 2 hurricane." << endl;
break;

case (108): 
cout << "This is a class 2 hurricane." << endl;
break;

case (109): 
cout << "This is a class 2 hurricane." << endl;
break;

case (110): 
cout << "This is a class 2 hurricane." << endl;
break;

case (111): 
cout << "This is a class 3 hurricane." << endl;
break;

case (112): 
cout << "This is a class 3 hurricane." << endl;
break;

case (113): 
cout << "This is a class 3 hurricane." << endl;
break;

case (114): 
cout << "This is a class 3 hurricane." << endl;
break;

case (115): 
cout << "This is a class 3 hurricane." << endl;
break;

case (116): 
cout << "This is a class 3 hurricane." << endl;
break;

case (117): 
cout << "This is a class 3 hurricane." << endl;
break;

case (118): 
cout << "This is a class 3 hurricane." << endl;
break;

case (119): 
cout << "This is a class 3 hurricane." << endl;
break;

case (120): 
cout << "This is a class 3 hurricane." << endl;
break;

case (121): 
cout << "This is a class 3 hurricane." << endl;
break;

case (122): 
cout << "This is a class 3 hurricane." << endl;
break;

case (123): 
cout << "This is a class 3 hurricane." << endl;
break;

case (124): 
cout << "This is a class 3 hurricane." << endl;
break;

case (125):
cout << "This is a class 3 hurricane." << endl;
break;

case (126): 
cout << "This is a class 3 hurricane." << endl;
break;

case (127): 
cout << "This is a class 3 hurricane." << endl;
break;

case (128): 
cout << "This is a class 3 hurricane." << endl;
break;

case (129): 
cout << "This is a class 3 hurricane." << endl;
break;

case (130): 
cout << "This is a class 3 hurricane." << endl;
break;

case (131): 
cout << "This is a class 4 hurricane." << endl;
break;

case (132): 
cout << "This is a class 4 hurricane." << endl;
break;

case (133): 
cout << "This is a class 4 hurricane." << endl;
break;

case (134): 
cout << "This is a class 4 hurricane." << endl;
break;

case (135): 
cout << "This is a class 4 hurricane." << endl;
break;

case (136): 
cout << "This is a class 4 hurricane." << endl;
break;

case (137): 
cout << "This is a class 4 hurricane." << endl;
break;

case (138): 
cout << "This is a class 4 hurricane." << endl;
break;

case (139): 
cout << "This is a class 4 hurricane." << endl;
break;

case (140): 
cout << "This is a class 4 hurricane." << endl;
break;

case (141): 
cout << "This is a class 4 hurricane." << endl;
break;

case (142): 
cout << "This is a class 4 hurricane." << endl;
break;

case (143): 
cout << "This is a class 4 hurricane." << endl;
break;

case (144): 
cout << "This is a class 4 hurricane." << endl;
break;

case (145): 
cout << "This is a class 4 hurricane." << endl;
break;

case (146): 
cout << "This is a class 4 hurricane." << endl;
break;

case (147): 
cout << "This is a class 4 hurricane." << endl;
break;

case (148): 
cout << "This is a class 4 hurricane." << endl;
break;

case (149): 
cout << "This is a class 4 hurricane." << endl;
break;
case (150): 
cout << "This is a class 4 hurricane." << endl;
break;

case (151): 
cout << "This is a class 4 hurricane." << endl;
break;

case (152): 
cout << "This is a class 4 hurricane." << endl;
break;

case (153): 
cout << "This is a class 4 hurricane." << endl;
break;

case (154): 
cout << "This is a class 4 hurricane." << endl;
break;


case (155): 
cout << "This is a class 5 hurricane." << endl;
break;

default: ;
cout << "This is a class 5 hurricane."; endl ;
}


return 0;
 }